package com.hlbspringcloud.springsecuritytoken.service;

import com.hlbspringcloud.springsecuritytoken.entity.JwtUser;
import com.hlbspringcloud.springsecuritytoken.entity.User;
import com.hlbspringcloud.springsecuritytoken.mapper.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author huanglibin
 * @Project spring-security-token
 * @Description 根据用户名去获取用户
 * @Date 2020-04-17-00-08-14
 * @Version 1.0
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userRepository.findByUsername(username);
        return new JwtUser(user);
    }
}
